#ifndef __H_THREAD_POOL_H__
#define __H_THREAD_POOL_H__

#include <cstdint>
#include <functional>
#include <thread>
#include <vector>
#include <atomic>

class ThreadPool
{
public:
    inline ThreadPool(std::function<void()> func, uint32_t num = 1)
    {
        for (auto i = 0; i < num; i++)
        {
            m_thread_pool.push_back(new std::thread([this, func]() {
                func();
                m_finish_num++;
            }));
        }
    }
    inline ~ThreadPool()
    {
        for (auto & thread : m_thread_pool)
        {
            thread->join();
            delete thread;
        }
        m_thread_pool.clear();
    }
    inline bool IsOver()
    {
        return m_finish_num == m_thread_pool.size();
    }

private:
    std::vector<std::thread*> m_thread_pool;
    std::atomic<std::int32_t> m_finish_num;
};













#endif 